test(regression): add regression test for issue #2410#2549
Conversation
Verify that PolicyPlugin generates valid SQL when related models share identical field names both protected by @deny rules. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job PR Review Complete ✅Todo List
Code Review FeedbackThis regression test for issue #2410 is well-structured and addresses the core issue effectively. The test verifies that PolicyPlugin generates valid SQL when parent and child models share identical field names with the same policy restrictions. ✅ Strengths
📝 Minor Suggestions
// Additional test case for Question model
await expect(
db.$setAuth(user).question.update({
where: { id: thread.questions[0].id },
data: { apiKeyId: 'key-3' },
}),
).toBeRejectedByPolicy();
// Tests that PolicyPlugin doesn't generate conflicting SQL aliases when
// multiple models have identically named fields with the same @deny policies🔍 Technical Analysis
🚀 Performance & Security
📊 Test Coverage AssessmentThe test coverage is good for the specific issue but could be enhanced:
📋 Recommendations
SummaryThis is a solid regression test that properly validates the fix for issue #2410. The test structure follows project conventions, uses appropriate testing utilities, and covers the essential scenarios. The code quality is excellent with clear intent and proper error handling. Approval recommendation: ✅ Approved - This test effectively prevents regression of the SQL generation bug when models share identically named policy-protected fields. |
📝 WalkthroughWalkthroughAdded a regression test file verifying policy enforcement correctly handles multiple related models with identically-named Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/regression/test/issue-2410.test.ts (1)
58-72: Consider extending coverage to also test the Question model's denied field.The PR description states the issue involves both
Thread.apiKeyIdandQuestion.apiKeyIdsharing identical@denyrules, but onlyThreadupdates are verified. TestingQuestion.apiKeyIdupdates would strengthen confidence that the SQL generation fix handles both parent and child models correctly.📝 Suggested additional assertions
// updating a denied field should succeed for admin await expect( db.$setAuth(admin).thread.update({ where: { id: thread.id }, data: { apiKeyId: 'key-2' }, }), ).toResolveTruthy(); + + // also verify the child model's denied field behaves correctly + const question = thread.questions?.[0] ?? (await db.$setAuth(admin).question.findFirst({ where: { threadId: thread.id } })); + + // updating denied field on Question should be rejected for non-admin + await expect( + db.$setAuth(user).question.update({ + where: { id: question.id }, + data: { apiKeyId: 'key-3' }, + }), + ).toBeRejectedByPolicy(); + + // updating denied field on Question should succeed for admin + await expect( + db.$setAuth(admin).question.update({ + where: { id: question.id }, + data: { apiKeyId: 'key-3' }, + }), + ).toResolveTruthy(); }); });Note: If the nested create doesn't return
questions, you may need to include{ include: { questions: true } }in the create call at line 40.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/regression/test/issue-2410.test.ts` around lines 58 - 72, Add assertions mirroring the Thread.apiKeyId checks for the Question model: after creating the thread with its questions (ensure the create includes { include: { questions: true } } if questions are not returned), assert that a non-admin user update of Question.apiKeyId via db.$setAuth(user).question.update({... where: { id: question.id }, data: { apiKeyId: 'key-2' } }) is rejected by policy and that the same update via db.$setAuth(admin).question.update(...) resolves truthily; locate the Question update calls by the db.$setAuth(...).question.update and question.id symbols to add these two expectations analogous to the Thread ones.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/regression/test/issue-2410.test.ts`:
- Around line 58-72: Add assertions mirroring the Thread.apiKeyId checks for the
Question model: after creating the thread with its questions (ensure the create
includes { include: { questions: true } } if questions are not returned), assert
that a non-admin user update of Question.apiKeyId via
db.$setAuth(user).question.update({... where: { id: question.id }, data: {
apiKeyId: 'key-2' } }) is rejected by policy and that the same update via
db.$setAuth(admin).question.update(...) resolves truthily; locate the Question
update calls by the db.$setAuth(...).question.update and question.id symbols to
add these two expectations analogous to the Thread ones.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 40a9881e-2bc3-423b-9ade-a1a7193db477
📒 Files selected for processing (1)
tests/regression/test/issue-2410.test.ts
Summary
Thread) and a child model (Question) share an identical field name (apiKeyId) both protected by@deny('all', auth().role != 'ADMIN')Test plan
TEST_DB_PROVIDER=sqlite vitest run test/issue-2410.test.tspasses🤖 Generated with Claude Code
Summary by CodeRabbit